// 题意：给定一个树，每个点有个权值ci，现在要给所有点染色，如果要染当前点
//       其父亲节点必须以经染色，如果在第ti个染当前点，那么所需费用为
//       ti * ci。现在要染所有点并且最小化 sigma(ti * ci)。
//
// 题解：贪心构造。每次将非根节点与根节点合并，合并点的权值是所有合并点的
//       权值和除以点的个数。然后合并到根节点所得到的顺序就是最后的顺序。
//       详细见blog。
//       
// 统计：64ms，1h10min，1re
//
// run: $exec < input
// opt: 0
// flag: -g
#include <cstdio>
#include <cstring>
#include <vector>

int const maxn = 1007;
bool merged[maxn];
int father[maxn];
int cost[maxn];
int cost_back[maxn];
int size[maxn];

int head[maxn], tail[maxn], next[2 * maxn], end_point[2 * maxn];
int alloc;

int n, r;

std::vector<int> graph[maxn];

void dfs(int u, int f)
{
	father[u] = f;
	for (int i = 0; i < (int)graph[u].size(); i++) {
		int v = graph[u][i];
		if (v == f) continue;
		dfs(v, u);
	}
}

int main()
{
	while (std::scanf("%d %d", &n, &r) && (n || r)) {
		alloc = 1;
		r--;
		std::memset(merged, 0, sizeof(merged));
		std::memset(head, 0, sizeof(head));
		std::memset(next, 0, sizeof(next));
		std::memset(tail, 0, sizeof(tail));
		for (int i = 0; i < n; i++) graph[i].clear();

		for (int i = 0; i < n; i++) {
			std::scanf("%d", &cost[i]);
			cost_back[i] = cost[i];
			size[i] = 1;
		}

		for (int i = 1, x, y; i < n; i++) {
			std::scanf("%d %d", &x, &y);
			x--;  y--;
			graph[x].push_back(y);
			graph[y].push_back(x);
		}

		dfs(r, -1);

		for (int i = 0; i < n-1; i++) {
			int mole = 0, deno = 1, pos; // mole / deno
			for (int j = 0; j < n; j++) {
				if (merged[j] || j == r) continue;
				if (mole * size[j] < deno * cost[j]) {
					mole = cost[j];
					deno = size[j];
					pos = j;
				}
			}

//			std::printf("--> %d %d\n", pos, cost[pos]);

			// merge
			merged[pos] = true;
			int f = father[pos];
			while (merged[f]) f= father[f];
			cost[f] += cost[pos];
			size[f] += size[pos];
			end_point[alloc] = pos;
			next[alloc] = head[pos];
			if (tail[f]) next[tail[f]] = alloc;
			else		 head[f] = alloc;
			tail[f] = alloc++;
			if (tail[pos]) tail[f] = tail[pos];
		}

		int ans = cost_back[r], ti = 2;
		for (int p = head[r]; p; p = next[p], ti++) {
			//std::printf("--> %d\n", end_point[p]);
			ans += ti * cost_back[end_point[p]];
		}
		std::printf("%d\n", ans);
	 }
}

